package cn.itcast.travel.service.impl;

import cn.itcast.travel.dao.UserDao;
import cn.itcast.travel.dao.impl.UserDaoImpl;
import cn.itcast.travel.domain.Category;
import cn.itcast.travel.domain.User;
import cn.itcast.travel.service.service;
import cn.itcast.travel.util.MailUtils;
import cn.itcast.travel.util.UuidUtil;

import java.util.Collections;
import java.util.List;

public class serviceImpl implements service {
    UserDao dao = new UserDaoImpl();
    public boolean register(User user) {
        User u =dao.findUserByUserName(user.getUsername());
        if(u!=null){
            return false;
        }
        user.setCode(UuidUtil.getUuid());
        user.setStatus("N");
        dao.save(user);
        String content = "<a href='http://127.0.0.1:8080/travel/user/active?code="+user.getCode()+"'>"+"点击激活"+"</a>";
            MailUtils.sendMail(user.getEmail(), "激活邮件",content);
        return true;
    }

    @Override
    public boolean active(String code) {
        User user= dao.finByCode(code);
        if(user!=null){
            dao.updateStatus(user);
            return true;
        }else {
            return false;
        }


    }

    @Override
    public User login(User user) {
        return dao.findByUserNameAndPassWord(user.getUsername(),user.getPassword());
    }
}
